package com.yyjj.my.adapter;

import android.view.View;
import android.widget.ImageView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.avos.avoscloud.AVUser;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.vise.xsnow.event.BusManager;
import com.yyjj.my.R;
import com.yyjj.my.activity.AboutActivity;
import com.yyjj.my.activity.FeedBackActivity;
import com.yyjj.my.cache.CacheData;
import com.yyjj.my.entity.LoopBean;

import tech.com.commoncore.base.BaseActivity;
import tech.com.commoncore.event.LoginChangeEvent;
import tech.com.commoncore.manager.GlideManager;
import tech.com.commoncore.utils.FastUtil;

/**
 * Desc:
 */
//          items.add(new LoopBean(R.mipmap.icon_icons_focus,"我的关注"));
//        items.add(new LoopBean(R.mipmap.icon_icons_community,"精华帖子"));
//        items.add(new LoopBean(R.mipmap.icon_icons_flash,"实时快讯"));
//        items.add(new LoopBean(R.mipmap.icon_feedback,"意见反馈"));
//        items.add(new LoopBean(R.mipmap.icon_risktip,"风险提示"));
//        items.add(new LoopBean(R.mipmap.icon_online_server,"在线客服"));
public class PersonalAdapter extends BaseQuickAdapter<LoopBean,BaseViewHolder> {

    public PersonalAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(final BaseViewHolder helper, LoopBean item) {
        helper.setText(R.id.tv_title,item.text);
        GlideManager.loadImg(item.img, (ImageView)helper.getView(R.id.iv_icon));

        helper.setOnClickListener(R.id.ll_item, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(helper.getPosition() ==0){
//                    ,"关于我们"));
//                    items.add(new LoopBean(R.mipmap.ic_launcher_round,"清除缓存"));
//                    items.add(new LoopBean(R.mipmap.ic_launcher_round,"意见反馈"));

                    FastUtil.startActivity(mContext, AboutActivity.class);
                }else if(helper.getPosition() ==1){
                    ((BaseActivity) mContext).showLoading("正在清理");
                    helper.getView(R.id.ll_item).postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            ((BaseActivity) mContext).hideLoading();
                        }
                    },1500);

                }else if (helper.getPosition() ==2){

                    FastUtil.startActivity(mContext,FeedBackActivity.class);
                }
//                else{
//                    if (AVUser.getCurrentUser() != null){
//                        getSignOut();
//                    }else {
//                        ARouter.getInstance().build("/my/ChangePassword").navigation();
//                    }
//
//                }
            }
        });

    }
    //登出
    private void getSignOut() {
        AVUser.logOut();// 清除缓存用户对象
        //清除登录信息
        CacheData.initLoginAccount(mContext,"",""); //缓存账号
        BusManager.getBus().post(new LoginChangeEvent(true)); //通知登录改变
        ARouter.getInstance().build("/login/login").navigation();
    }
}
